package tag

var (
	_ SensitiveTagOutputHandler = new(SensitiveTokenTagOutputHandler)
)

type SensitiveTokenTagOutputHandler struct {
}

func (h *SensitiveTokenTagOutputHandler) DesensitizeTag(systemTag any, tag string) string {
	patternedSystemTag, isOk := systemTag.(*PatternedSystemTag)
	if !isOk {
		return tag
	}

	sensitiveTokens := patternedSystemTag.Annotation.Tokens()
	if len(sensitiveTokens) == 0 {
		return tag
	}

	tokens := patternedSystemTag.GetTokensByTag(tag)
	if len(tokens) == 0 {
		return tag
	}

	for _, t := range sensitiveTokens {
		tokens[t] = "*****"
	}

	return patternedSystemTag.InstantiateTag(tokens)
}
